package com.ycode.bang.anbang.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;

import com.ycode.bang.anbang.R;
import com.ycode.bang.anbang.utils.SetImage;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by maosongsong on 2016/4/6.
 */
public class ImageAdapter extends ArrayAdapter<String> {
    private LayoutInflater layoutInflater;
    public List<String> mInfoList;
    public Context context;

    public ImageAdapter(Context context, List<String> objects) {
        super(context, 0, objects);
        mInfoList = new ArrayList<>();
        mInfoList = objects;
        layoutInflater = LayoutInflater.from(context);
        this.context = context;

    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (null == convertView) {
            convertView = layoutInflater.inflate(R.layout.item_image, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        SetImage.setimage(context,mInfoList.get(position), holder.infoImage);
        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.image)
        ImageView infoImage;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }

    @Override
    public int getCount() {
        return mInfoList.size();
    }
}
